//初始化单页view
var viewApi = mui('#app').view({
    defaultPage: '#setting'
});
//初始化单页的区域滚动
mui('.mui-scroll-wrapper').scroll();

var view = viewApi.view;
(function($) {
    //处理view的后退与webview后退
    var oldBack = $.back;
    $.back = function() {
        if (viewApi.canBack()) { //如果view可以后退，则执行view的后退
            viewApi.back();
        } else { //执行webview后退
            oldBack();
        }
    };
    //监听页面切换事件方案1,通过view元素监听所有页面切换事件，目前提供pageBeforeShow|pageShow|pageBeforeBack|pageBack四种事件(before事件为动画开始前触发)
    //第一个参数为事件名称，第二个参数为事件回调，其中e.detail.page为当前页面的html对象
    view.addEventListener('pageBeforeShow', function(e) {
        //				console.log(e.detail.page.id + ' beforeShow');
    });
    view.addEventListener('pageShow', function(e) {
        //				console.log(e.detail.page.id + ' show');
    });
    view.addEventListener('pageBeforeBack', function(e) {
        //				console.log(e.detail.page.id + ' beforeBack');
    });
    view.addEventListener('pageBack', function(e) {
        //				console.log(e.detail.page.id + ' back');
    });
})(mui);


//步骤1:触发点击事件
function next() {
    var btn = document.getElementById("toNext");
    btn.addEventListener("tap", function () {
        console.log("tap toNext trigger");
    });
    mui.trigger(btn,'tap');
}

//步骤2:触发点击事件
function next2() {
    var btn = document.getElementById("toEnd");
    btn.addEventListener("tap", function () {
        console.log("tap toEnd trigger");
    });
    mui.trigger(btn,'tap');
}

mui.ready(function () {
    // 步骤1:下一步
    mui(".mui-button-df").on('tap', "#next", function () {
        console.log("tap event 112");
        // 数据
        var realname = mui("#realname")[0].value;
        var cardno = mui("#cardno")[0].value;
        var data = {
            realname:realname,
            cardno:cardno,
        }

        next()
    })

    //  提示
    mui(".mui-input-row").on('tap',".mui-phone-btn",function () {
        var text = "银行预留的手机号是办理该银行卡时所填写的手机号码。没有预留、手机号忘记或者停用，请联系银行客服更新处理。";
        mui.alert(text);
    })

    var isOk; // 同意协议
    // 同意协议
    mui('.mui-row').on('change', 'input', function() {
        // var value = this.checked?"true":"false";
        // this.previousElementSibling.innerText = "checked："+value;
        if(this.checked){
            // mui.alert("同意协议")
            isOk = true;
        }else{
            isOk = false;
        }
    });

    // 步骤2:下一步
    mui(".mui-button-df").on("tap","#next2",function () {
        if(!isOk){
            // mui.alert("请先同意协议"); return;
        }
        // 数据
        var idcard = mui("#idcard")[0].value;
        var phone = mui("#phone")[0].value;
        next2()
    })

    // 步骤2:提交
    mui(".mui-button-df").on("tap","#submit",function () {
        // 数据
        var idcard = mui("#idcard")[0].value;
        var phone = mui("#phone")[0].value;
        var phonecode = mui("#phoneCode")[0].value;
        var data = {
            idcard:idcard,
            phone:phone,
            phonecode:phonecode,
        }
        // 执行提交
        // request("bind.do",data,function (res) {
        // })
    })

})



